package com.smec.remes.module.drafts;

import android.content.Context;
import android.util.Log;

import com.smec.remes.base.SmecBasePresenter;
import com.smec.remes.bean.DraftsDelete;
import com.smec.remes.bean.RequestSearch;
import com.smec.remes.bean.SubmitApply;
import com.smec.remes.smecManager.SmecRetrofit.BaseSubscriber;
import com.smec.remes.smecManager.SmecRetrofit.HttpResult;

import java.util.ArrayList;
import java.util.HashMap;

import rx.Observable;

/**
 * Created by Administrator on 2017/12/8.
 */

public class SmecDraftsPresenter extends SmecBasePresenter {
    public SmecDraftsPresenter(Context mContext) {
        super(mContext);
    }

    public  void getDrafts(){
        HashMap<String,Object> map=new HashMap<>();
        map.put("condition","");
        map.put("type","NEW");
        map.put("pageSize",10);
        map.put("pageNumber",1);
        Observable<HttpResult<ArrayList<RequestSearch>>> observable=smecPackingService.requestSearch(map);
        schedulerThread(observable).subscribe(new BaseSubscriber<HttpResult<ArrayList<RequestSearch>>>() {
            @Override
            public void onNext(HttpResult<ArrayList<RequestSearch>> arrayListHttpResult) {
                 mRxbus.post("DRAFTS",arrayListHttpResult.getData());
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                mRxbus.post("DRAFTSFAIL",e.toString());
            }
        });
    }

    public void daftsDelete(DraftsDelete draftsDelete){
        Observable<HttpResult> observable=smecPackingService._draftsDelete(draftsDelete);
        schedulerThread(observable).subscribe(new BaseSubscriber<HttpResult>() {
            @Override
            public void onNext(HttpResult httpResult) {
                mRxbus.post("DELETE",httpResult);
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                mRxbus.post("DELETEFAIL",e.toString());
            }
        });
    }
}
